package com.hdaccp.supermarket;

import com.hdaccp.supermarket.dao.SmbmsUserDao;
import com.hdaccp.supermarket.entity.SmbmsUser;
import com.hdaccp.supermarket.util.BaseDao;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

public class Test extends BaseDao {
    public   void testQuerySmbmsUser(){
        //1.得到数据库连接
        SqlSession session = super.getSession() ;
        SmbmsUserDao smbmsUserDao = session.getMapper(SmbmsUserDao.class) ;
        List<SmbmsUser> list = smbmsUserDao.query() ;
        for(SmbmsUser user : list){
            System.out.println(user.getId() + "----" + user.getUserCode() + "--" + user.getUserName()) ;
        }
        session.close();
    }

    public   void testUpdateSmbmsUser() {
        //1.得到数据库连接
        SqlSession session = super.getSession();
        SmbmsUserDao smbmsUserDao = session.getMapper(SmbmsUserDao.class);

        SmbmsUser user = new SmbmsUser() ;
        user.setAddress("河北邯郸");
        user.setId(2);
        smbmsUserDao.update(user) ;
        session.commit();
        session.close();
    }

    public void testQueryByIn(){

            //1.得到数据库连接
            SqlSession session = super.getSession();
            SmbmsUserDao smbmsUserDao = session.getMapper(SmbmsUserDao.class);
            int[] ids = new int[]{1,2,5} ;
            List<SmbmsUser> list =  smbmsUserDao.queryByIn(ids) ;
            for(SmbmsUser user : list){
                System.out.println(user.getId() + "----" + user.getUserCode() + "--" + user.getUserName()) ;
            }
        session.close();

    }

    public void testQueryByList(){

        //1.得到数据库连接
        SqlSession session = super.getSession();
        SmbmsUserDao smbmsUserDao = session.getMapper(SmbmsUserDao.class);
        List<Integer> list = new ArrayList<>() ;
        list.add(1) ;
        list.add(2) ;
        list.add(5) ;
        List<SmbmsUser> list1 =  smbmsUserDao.queryByList(list) ;
        for(SmbmsUser user : list1){
            System.out.println(user.getId() + "----" + user.getUserCode() + "--" + user.getUserName()) ;
        }
        session.close();

    }
    public static void main(String[] args) {
        Test test = new Test() ;
       // test.testQuerySmbmsUser();
        test.testQueryByList() ;
    }
}
